package com.esoon.service.impl;

import com.esoon.dao.SoftphoneCallDao;
import com.esoon.entity.SoftphoneCall;
import com.esoon.service.SoftPhoneCallService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName SoftphoneCallServiceImpl
 * @Description TODO
 * @Author 2020/9/29 22:54
 * @Version 1.0
 **/
@Service
public class SoftPhoneCallServiceImpl implements SoftPhoneCallService {
    @Resource
    private SoftphoneCallDao softphoneCallDao;
    /**
     * @Author Jack
     * @Description //TODO 查询的结果大于等于2次返回1，小于2次返回0，程序错误返回2
     * @Date 22:57 2020/9/29
     * @Param [startDate, endDate, phone]
     * @return int
     **/

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CsrWorkTimeServiceImpl.class);
    }

    //如果查询到的数据大于2条，返回 1 如果查询到的数据小于2条，返回0 程序错误返回500
    @Override
    public String selectAbandonPhone(String startDate, String endDate, String phone) {
        String result = "0";
        try{
           int count = softphoneCallDao.selectAbandonPhone(startDate, endDate, phone);
            if (count >= 2){
                result = "1";
            }else{
                result = "0";
            }
        }catch (Exception e){
            logger.error(e.toString());
            result = "2";
        }

        return result;
    }

    @Override
    public String updateCLHangupByConnId(String connId) {
        String result = "";
        try{
            softphoneCallDao.updateCLHangupByConnId(connId);
            result = "1";
            logger.info("根据connid更新放弃类型成功");
            return result;
        }catch (Exception e){
            result = "500";
            logger.error(e.toString());
            return result;
        }
    }

    @Override
    public String insert(String connid, String ani, String dnis, String dep) {
        SoftphoneCall softphoneCall = new SoftphoneCall();
        softphoneCall.setClConnid(connid);
        softphoneCall.setClAni(ani);
        softphoneCall.setClDni(dnis);
        softphoneCall.setClChannel("voice");
        softphoneCall.setClType("呼入");
        softphoneCall.setClAgentDn("0");


        softphoneCall.setCreateTime(new Date());
        softphoneCall.setTenantId(1);
        softphoneCall.setTenantName(dep);
        softphoneCall.setClHangup("102");
        try{
            softphoneCallDao.insert(softphoneCall);
            logger.info("插入成功");
            return "0";
        }catch (Exception e){
            logger.error("插入失败"+e.toString());
            return "500";
        }
    }
}
